using UnityEngine;

public class WindowsRect : MonoBehaviour
{
    private UIRoot uIRoot;
    private UIGrid subGrid;
    //此脚本放在大厅主界面上 

    private int minWidth = 750;

  
    void Awake()
    {
        GetComponent<UIScrollView>().onDragStarted += () => { };

        minWidth = Screen.width < minWidth ? Screen.width : minWidth;

        //1080  1920   750  1633
        // int w = Screen.width;
        //  int h = Screen.height
   /*     if ((float)Screen.height/ Screen.width> (float)1633/ minWidth)
        {
            return;
        }*/
          int w = minWidth;
          int h = (int)(750* ((float)Screen.height / Screen.width));
        if(minWidth<750)
        {
            w = 750;
            h = (int)(Screen.height* ((float)750/ Screen.width));
        }else
        {
           // h = (int)(Screen.height * ((float)750 / Screen.width));
        }
        //统一宽度750 
        //
        /*   int w = 750;
           float dif = ((float)Screen.width / 750);
           int h = (int)( dif * 1334);*/

        uIRoot = GameObject.Find("2DUIRoot").GetComponent<UIRoot>();
        uIRoot.manualHeight = h;
        uIRoot.manualWidth = w;

        Transform tempGrid = transform.Find("Grid");
        subGrid = tempGrid.GetComponent<UIGrid>();


        subGrid.cellWidth = w;
        subGrid.cellHeight = h;
 
        for (int i=0;i<5;i++)
        {
             
            tempGrid.GetChild(i).GetComponent<UISprite>().width = w;
            tempGrid.GetChild(i).GetComponent<UISprite>().height =h;
        }
        GetComponent<UIPanel>().Refresh();
        GetComponent<UIPanel>().clipRange = new Vector4(0, 0,w, h);
        GetComponent<UIPanel>().clipOffset = new Vector2(0, 0);
        transform.localPosition = new Vector3(0, 0, 0);
    }

    private void OnEnable()
    {
        
        // 添加分辨率改变事件监听器
        
    }

}
